/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-29 20:25:10
 * @LastEditTime: 2021-08-29 20:26:25
 * @LastEditors: changqing
 * @Usage: 
 */

const p = new Promise((resolve) => {
  console.log('Promise 执行了');
  setTimeout(() => {
    resolve(100);
  }, 1000);
});

p.then(result => {
  console.log(`Promise 处理结果: ${result}`);
});
// Promise 执行了
// Promise 处理结果: 100



// 可以看到Promise excute立即执行了如果此时我们不想让Promise excuete立即执行，做一个延迟lazy 执行那么就该defer上场了
var { defer,of } = require('rxjs');
const promiseFactory = () =>
   new Promise((resolve) => {
     console.log("Promise 执行了");
     setTimeout(() => {
     resolve(100);
     }, 1000);
   });
   const deferSource = defer(promiseFactory);
   // 此時 Promise 内 excute 不会立马执行
   console.log("示范用 defer 解決 Promise 的问题:");
   // 直到被订阅了才会执行 promise excute
   deferSource.subscribe((result) => {
   console.log(`Promise 结果: ${result}`);
   });